Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

120
Visualizações
How to set headers of stream response so I can infer then on next stream.on("data", ()=>{}) handler in Node.js?

Background: I am trying to be able to make some unique identifier for each client that connects and stream to my service such that whenever they make a new request I can detect and block them from restreaming from my site until they stop the current stream.

DISCLAIMER: I am new to streaming, I was hoping that maybe on the New request object somewhere I would be able to tall if a user is streaming. I think somehow this is can be for socket application

Bellow is my code so far. The idea is to somehow be able to tell how many stream each client(Broswer) is streaming on each time they send request to my server.

app.get('/video', function (req, res) {

  const path = 'abc.mp4'
  const stat = fs.statSync(path)
  const fileSize = stat.size
  const range = req.headers.range

  if (range) {
    // console.log("Has range: ", range)
    const parts = range.replace(/bytes=/, "").split("-")
    const start = parseInt(parts[0], 10)
    const end = parts[1]
      ? parseInt(parts[1], 10)
      : fileSize - 1

    const chunksize = (end - start) + 1
    const file = fs.createReadStream(path, { start, end })

    const head = {
      'Content-Range': `bytes ${start}-${end}/${fileSize}`,
      'Accept-Ranges': 'bytes',
      'Content-Length': chunksize,
      'Content-Type': 'video/mp4',
      'MY_UNIQUE_ID': "Hello World" + new Date().toISOString()
    }



    res.writeHead(206, head)

    file.pipe(res)

    file.on("data", function (chunk) {
      if (!!req.headers) {
        //Expecting to also have MY_UNIQUE_ID
        console.log(req.headers)
      }
    });

  }
})
about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda